<?php
// +----------------------------------------------------------------------
// | 知识星球[基于ThinkPHP5开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2019 abcblockchain.io
// +----------------------------------------------------------------------
// | 后台管理使用了HisiPHP
// +----------------------------------------------------------------------
// | Author: abcblockchain.io
// +----------------------------------------------------------------------
namespace app\index\home;

use app\common\controller\Common;
use think\Db;
use app\common\model\Group as groupModel;
use app\common\model\GroupPosts as postModel;

class Share extends Common
{

    /**
     * 初始化方法
     */
    protected function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 班级分享
     * @author
     * @return string
     * @throws \think\Exception
     */
    public function shareClass(){
        if (isset($_GET['groupId']) && $_GET['groupId']) {
            $groupId = $_GET['groupId'];
            $postModel = new postModel();
            $groupModel = new groupModel();
            $groupInfo = $groupModel->groupInfo($groupId);
            if ($groupInfo) {
                $groupInfo['essences'] = $postModel->where('group_id', $groupId)->where('disabled', 1)->where('is_essence', 1)->count('id');
               /* $vnsInfo = Db::name('currency')->where('id',2)->field('last_price')->find();
                $groupInfo['vnsPrice'] = $vnsInfo['last_price'];*/
                $groupInfo['cday'] = ceil((time() - strtotime($groupInfo['ctime'])) / 86400);
            }
            $postList = $postModel->postList($groupId, 0, 6);
            if ($groupInfo) {
                $data['groupInfo'] = $groupInfo;
                $data['postList'] = $postList;
                $this->assign('groupInfo',$data);
                return $this->fetch();
            } else {
                $this->error("分享班级不存在");
            }

        } else {
            $this->error("分享班级不存在");
        }
    }


    public function sharePost(){
        if (isset($_GET['postId']) && $_GET['postId']) {
            $postModel = new postModel();
            $postId = $_GET['postId'];
            $postInfo = $postModel->postDetail($postId);
            if($postInfo){
                $this->assign('postInfo',$postInfo);
                return $this->fetch();
            }else{
                $this->error("分享帖子不存在");
            }
        } else {
            $this->error("分享帖子不存在");
        }
    }

}